package temp;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class CsvRowCountDriver {
    public static void main(String[] args) throws Exception {
        if (args.length != 2) {
            System.err.println("Usage: temp.CsvRowCountDriver <input> <output>");
            System.exit(1);
        }

        Configuration conf = new Configuration();


        Job job = Job.getInstance(conf, "CSV Row Count");
        job.setJarByClass(CsvRowCountDriver.class);
        job.setMapperClass(CsvRowCountMapper.class);
        job.setReducerClass(CsvRowCountReducer.class);

        // 关键：设置 Mapper 和 Reducer 的输出键值类型
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(LongWritable.class); // 必须是 LongWritable

        FileInputFormat.addInputPath(job, new Path(args[0])); // HDFS 输入路径
        FileOutputFormat.setOutputPath(job, new Path(args[1])); // HDFS 输出路径

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
